package com.gem.mapper;

import com.gem.domain.CompanyVisit;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Bravea❤ ·勇
 * Description: 企业拜访记录mapper
 * create
 * Modified By:
 */
@Mapper
public interface CompanyVisitMapper {
    //插入
    @Insert("INSERT INTO company_visit (com_visit_company_id,com_visit_date,com_visit_initiator_id,com_visit_purpose,com_visit_visitor,com_visit_type,com_visit_details," +
            "com_visit_remarks) VALUES (#{comVisitCompanyId},#{comVisitDate},#{comVisitInitiatorId},#{comVisitPurpose},#{comVisitVisitor},#{comVisitType},#{comVisitDetails},#{comVisitRemarks})")
    boolean addCompanyVisit(CompanyVisit c);

    //查找所有
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE co_id=com_visit_company_id AND com_visit_initiator_id=uid AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectAllCompanyVisit();

    //查找所有企培
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE co_id=com_visit_company_id AND com_visit_initiator_id=uid AND job='企培' AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectCompanyVisitE();

    //查找所有就业
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE co_id=com_visit_company_id AND com_visit_initiator_id=uid AND job='就业' AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectCompanyVisitJ();

    //查找自己所有的
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE co_id=com_visit_company_id AND com_visit_initiator_id=uid AND personname=#{personname} AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectMyCompanyVisit(String  personname);

    //查询单个拜访记录
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE co_id=com_visit_company_id AND com_visit_initiator_id=uid AND com_visit_id = #{com_visit_id} AND com_visit_status>0")
    CompanyVisit selectCompanyVisitById(String com_visit_id);

    //查询单个公司的所有拜访记录
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE com_visit_company_id = #{comVisitCompanyId}  AND co_id=com_visit_company_id AND com_visit_initiator_id=uid AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectCompanyVisitByCompanyId(String comVisitCompanyId);

    //查询单个公司的企培拜访记录
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE com_visit_company_id = #{comVisitCompanyId}  AND co_id=com_visit_company_id AND com_visit_initiator_id=uid AND job='企培' AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectCompanyVisitEByCompanyId(String comVisitCompanyId);

    //查询单个公司的就业拜访记录
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE com_visit_company_id = #{comVisitCompanyId}  AND co_id=com_visit_company_id AND com_visit_initiator_id=uid AND job='就业' AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectCompanyVisitJByCompanyId(String comVisitCompanyId);

    //查询单个公司的自己的拜访记录
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company,company_visit WHERE com_visit_company_id = #{param1}  AND co_id=com_visit_company_id AND com_visit_initiator_id=uid AND personname=#{param2} AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> selectMyCompanyVisitByCompanyId(String comVisitCompanyId,String personname);

    //修改
    @Update("UPDATE company_visit SET com_visit_company_id=#{comVisitCompanyId},com_visit_date=#{comVisitDate},com_visit_initiator_id=#{comVisitInitiatorId}," +
            "com_visit_purpose=#{comVisitPurpose},com_visit_visitor=#{comVisitVisitor},com_visit_type=#{comVisitType},com_visit_details=#{comVisitDetails}," +
            "com_visit_remarks=#{comVisitRemarks} WHERE com_visit_id=#{comVisitId} AND com_visit_status>0")
    boolean modifyCompanyVisitById(CompanyVisit c);

    //@Delete("DELETE FROM company_visit WHERE com_visit_id=#{com_visit_id}")//真删
    //伪删除
    @Update("UPDATE company_visit SET com_visit_status=-1 WHERE com_visit_id=#{com_visit_id}")
    boolean deleteCompanyVisitById(String com_visit_id);

    //查询带条件 全部
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company_visit,company WHERE co_id=com_visit_company_id AND uid=com_visit_initiator_id AND co_name LIKE #{param1} AND personname LIKE #{param2} AND com_visit_date LIKE #{param3} AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> searchCompanyVisit(String com_visit_company_name, String com_visit_initiator, String com_visit_date);

    //查询带条件 企培
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company_visit,company WHERE co_id=com_visit_company_id AND uid=com_visit_initiator_id AND job='企培' AND co_name LIKE #{param1} AND personname LIKE #{param2} AND com_visit_date LIKE #{param3} AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> searchCompanyEVisit(String comVisitCompanyName, String comVisitInitiator, String str_comVisitDate);

    //查询带条件 就业
    @Select("SELECT company_visit.*,co_name,personname FROM `user`,company_visit,company WHERE co_id=com_visit_company_id AND uid=com_visit_initiator_id AND job='就业' AND co_name LIKE #{param1} AND personname LIKE #{param2} AND com_visit_date LIKE #{param3} AND com_visit_status>0 ORDER BY com_visit_date DESC")
    List<CompanyVisit> searchCompanyjVisit(String comVisitCompanyName, String comVisitInitiator, String str_comVisitDate);
}
